home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / lan.zip / LAN.REV < prev    next >
Text File  |  1991-07-18  |  6KB  |  314 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <bios.h>
  4. #include <cxldef.h>
  5. #include <cxlvid.h>
  6.  
  7. #define PORT  0   /*  Port Assignements 0 = Com 1 etc... */
  8. #define PORT1 1
  9. #define PORT2 2
  10. #define PORT3 3
  11.  
  12. unsigned int filesize();
  13.  
  14. void sport();
  15. void send_file();
  16. void rec_file();
  17. void get_file_name();
  18. void send_file_name();
  19. void port_init();
  20. void wait();
  21.  
  22. /************************************/
  23. error_clear()
  24. {
  25.  delay (1500);
  26.  gotoxy (18,23);
  27.  printf ("                                          ");
  28. }
  29.  
  30. /************************************/
  31. main()
  32. {
  33.  hidecur();
  34.  clrscr();
  35.  printf ("                    Lights of American Data Control Systems\n\n");
  36.  printf ("                               Local Area Network\n\n\n\n\n");
  37.  printf ("                             Revision 1.00 Beta Test\n");
  38.  printf ("                                 July, 17, 1991\n\n\n");
  39.  printf ("                             Press ANY KEY to abort!\n");
  40.  gotoxy (1,18);
  41.  printf ("┌──────────────────────────────────────┬───────────────────────────────────────┐");
  42.  gotoxy (1,19);
  43.  printf ("│ Date:                                │ Time:                                 │");
  44.  gotoxy (1,20);
  45.  printf ("├──────────────────────────────────────┼───────────────────────────────────────┤");
  46.  gotoxy (1,21);
  47.  printf ("│ Sending:                             │ Receiving:                            │");
  48.  gotoxy (1,22);
  49.  printf ("├──────────────────────────────────────┴───────────────────────────────────────┤");
  50.  gotoxy (1,23);
  51.  printf ("│ Error Messages:                                                              │");
  52.  gotoxy (1,24);
  53.  printf ("└──────────────────────────────────────────────────────────────────────────────┘");
  54.  
  55.  port_init(PORT1);
  56.  do
  57.  {
  58.   gotoxy (9,19);
  59.   printf ("%s",sysdate(0));
  60.   gotoxy (48,19);
  61.   printf ("%s",systime(0));
  62.   gotoxy (12,21);
  63.   printf ("                           ");
  64.   gotoxy (53,21);
  65.   printf ("                       ");
  66.   if (check_stat(PORT1) & 256)
  67.   {
  68.    switch (rport(PORT1))
  69.    {
  70.     case 's': send_file(PORT1); break;
  71.     case 'r': rec_file(PORT1); break;
  72.    }
  73.   }
  74.  }
  75.  while (!kbhit());
  76.  clrscr();
  77. }
  78. /*************************/
  79. void send_file(port)
  80. int port;
  81. {
  82.  FILE *fp;
  83.  char ch,fname[14];
  84.  union
  85.  {
  86.   char c[2];
  87.   unsigned int count;
  88.  } cnt;
  89.  sport(port,'.');
  90.  
  91.  get_file_name(fname,PORT1);
  92.  if (!(fp=fopen(fname,"rb")))
  93.  {
  94.   gotoxy (19,23);
  95.   printf ("Cannot open input file!");
  96.   exit (1);
  97.   error_clear();
  98.  }
  99.  if (rport(port) != '.')
  100.  {
  101.   gotoxy (19,23);
  102.   printf ("Remote file failure\n");
  103.   exit (1);
  104.   error_clear();
  105.  }
  106.  gotoxy (12,21);
  107.  printf ("%s\n",fname);
  108.  cnt.count = filesize(fp);
  109.  sport (port,cnt.c[0]);
  110.  wait (port);
  111.  
  112.  sport (port,cnt.c[1]);
  113.  do
  114.  {
  115.   ch = getc(fp);
  116.   if (ferror(fp))
  117.   {
  118.    gotoxy (19,23);
  119.    printf ("Error reading input file");
  120.    error_clear();
  121.    break;
  122.   }
  123.   if (!feof(fp))
  124.   {
  125.    wait (port);
  126.    sport(port,ch);
  127.   }
  128.  }
  129.  while (!feof(fp));
  130.  wait (port);
  131.  fclose(fp);
  132. }
  133.  
  134. /********************************/
  135. void rec_file(port)
  136. int port;
  137. {
  138.  FILE *fp;
  139.  char ch, fname[14];
  140.  union
  141.  {
  142.   char c[2];
  143.   unsigned int count;
  144.  } cnt;
  145.  sport (port,'.');
  146.  
  147.  get_file_name (fname,PORT1);
  148.  
  149.  gotoxy (53,21);
  150.  printf ("%s\n",fname);
  151.  /*remove (fname); */
  152.  if (!(fp=fopen(fname,"wb")))
  153.  {
  154.   gotoxy (19,23);
  155.   printf ("Cannot open output file\n");
  156.   exit (1);
  157.   error_clear();
  158.  }
  159.  sport (port,'.');
  160.  cnt.c[0] = rport (port);
  161.  sport (port,'.');
  162.  cnt.c[1] = rport (port);
  163.  sport (port,'.');
  164.  
  165.  for (; cnt.count; cnt.count --)
  166.  {
  167.   ch = rport (port);
  168.   putc (ch,fp);
  169.   if (ferror(fp))
  170.   {
  171.    gotoxy (19,23);
  172.    printf ("Error writing file.\n");
  173.    exit (1);
  174.    error_clear();
  175.   }
  176.   sport (port,'.');
  177.  }
  178.  fclose(fp);
  179. }
  180.  
  181. /***********************************/
  182. unsigned int filesize(fp)
  183. FILE *fp;
  184. {
  185.  unsigned long int i;
  186.  i = 0;
  187.  do
  188.  {
  189.   getc(fp);
  190.   i++;
  191.  }
  192.  while (!feof(fp));
  193.  rewind (fp);
  194.  return i-1;
  195. }
  196.  
  197. /***********************************/
  198. void send_file_name (f,port)
  199. char *f;
  200. int port;
  201. {
  202.  do
  203.  {
  204.   sport (port,'?');
  205.  }
  206.  while (!kbhit() && !(check_stat(port) & 256));
  207.  if (kbhit())
  208.  {
  209.   getch();
  210.   exit (1);
  211.  }
  212.  wait (port);
  213.  while (*f)
  214.  {
  215.   sport (port, *f++);
  216.   wait (port);
  217.  }
  218.  sport (port,0);
  219. }
  220.  
  221. /********************************/
  222. void get_file_name (f,port)
  223. char *f;
  224. int port;
  225. {
  226.  while (rport(port) != '?') printf (".");
  227.  sport (port,'.');
  228.  while ((*f=rport (port)))
  229.  {
  230.   if (*f!='?')
  231.   {
  232.    f++;
  233.    sport (port, '.');
  234.   }
  235.  }
  236.  sport (port,'.');
  237. }
  238.  
  239. /********************************/
  240. void wait (port)
  241. int port;
  242. {
  243.  if (rport (port) !='.')
  244.  {
  245.   gotoxy (19,23);
  246.   printf ("Communication Error\n");
  247.   exit (1);
  248.   error_clear();
  249.  }
  250. }
  251.  
  252. /*********************************/
  253. void sport (port,c)
  254. int port;
  255. char c;
  256. {
  257.  union REGS r;
  258.  r.x.dx = port;
  259.  r.h.al = c;
  260.  r.h.ah = 1;
  261.  int86 (0x14,&r,&r);
  262.  if (r.h.ah & 128)
  263.  {
  264.   gotoxy (19,23);
  265.   printf ("Send error detected in serial port");
  266.   exit (1);
  267.   error_clear();
  268.  }
  269. }
  270.  
  271. /*************************************/
  272. rport (port)
  273. int port;
  274. {
  275.  union REGS r;
  276.  while (!(check_stat (port) & 256))
  277.  if (kbhit())
  278.  {
  279.   getch();
  280.   exit (1);
  281.  }
  282.  r.x.dx = port;
  283.  r.h.ah = 2;
  284.  int86 (0x14,&r,&r);
  285.  if (r.h.ah & 128)
  286.  {
  287.   gotoxy (19,23);
  288.   printf ("Read error detected in serial port.\n");
  289.   error_clear();
  290.  }
  291.  return (r.h.al);
  292. }
  293.  
  294. /***********************************/
  295. check_stat (port)
  296. int port;
  297. {
  298.  union REGS r;
  299.  r.x.dx = port;
  300.  r.h.ah = 3;
  301.  int86 (0x14,&r,&r);
  302.  return r.x.ax;
  303. }
  304.  
  305. /**************************************/
  306. void port_init (port)
  307. int port;
  308. {
  309.  union REGS r;
  310.  r.x.dx = port;
  311.  r.h.al = 0;
  312.  r.h.al = 251;
  313.  int86 (0x14,&r,&r);
  314. }